<template>
  <div class="container">
    <div class="cont-header">
      <div class="info-item">
        <img class="pic" :src="personal.headUrl" alt="" />
        <div class="info">
          <div class="name">
            <p>
              {{ personal.name }}
              <i class="iconf iconbianji" @click="_UpdateProperty"></i>
            </p>
            <div class="operation">
              <!-- <p class="linkSetDetail" @click="linkSetDetail">
                档案信息不够丰富？点击添加更多线索
              </p> -->
              <button class="btn update" @click="_PersonOrgUpdata()">
                更新档案
              </button>
              <!-- <a href="javascript:;" class="btn down" @click="_GenerateReport()"
                >导出报告</a
              > -->
            </div>
          </div>
          <p class="time">
            <span>上次更新时间：{{ personal.updateTime }}</span>
            <span>当前更新进度：{{ personal.progress }}%</span>
          </p>
          <div class="label">
            <p
              class="label-list"
              :class="LabelshowAll ? 'overf' : ''"
              ref="labelList"
            >
              <span v-for="(item, index) in personal.label" :key="index">{{
                item
              }}</span>
            </p>
            <div class="label-set">
              <!-- <i class="iconf iconbianji"></i> -->
              <span
                class="more"
                v-if="LabelButtonShow"
                @click="LabelshowAll = !LabelshowAll"
              >
                查看更多<i
                  :class="[
                    'jt',
                    'el-icon-d-arrow-right',
                    !LabelshowAll ? 'rot' : '',
                  ]"
                ></i>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <ul class="tab">
      <li :class="tabType == 0 ? 'active' : ''" @click="setTabType(0)">简介</li>
      <li :class="tabType == 1 ? 'active' : ''" @click="setTabType(1)">
        能影响谁
      </li>
      <li :class="tabType == 2 ? 'active' : ''" @click="setTabType(2)">
        被谁影响
      </li>
      <li :class="tabType == 3 ? 'active' : ''" @click="setTabType(3)">
        被谁反对
      </li>
    </ul>
    <ul class="child-tab" v-show="tabType != 0">
      <li
        :class="childTabType == 0 ? 'active' : ''"
        @click="setChildTabType(0)"
      >
        人物({{ perNumber }})
      </li>
      <li
        :class="childTabType == 1 ? 'active' : ''"
        @click="setChildTabType(1)"
      >
        机构({{ orgNumber }})
      </li>
      <li
        v-show="tabType != 2"
        :class="childTabType == 2 ? 'active' : ''"
        @click="setChildTabType(2)"
      >
        推特({{ twitterNumber }})
      </li>
    </ul>
    <div class="cont-body" v-show="tabType == 0">
      <div class="body-left">
        <div class="basic-info">
          <p class="txt">{{ personal.abstractType }}</p>
          <ul class="basic-ul" :class="personalInfoShowAll ? 'no' : ''">
            <li v-for="(item, index) in personalInfo" :key="index">
              <span class="ellipsis s1">{{ item.name }}</span>
              <el-popover class="p1 ellipsis2" placement="bottom-start">
                <div class="set-icon">
                  <i class="iconf iconcheck-line" @click="sayDetail(item)"></i>
                  <i class="iconf iconbianji" @click="setItem(item)"></i>
                  <i
                    class="iconf iconicon_anquan"
                    :class="item.verified ? 'active' : ''"
                    @click="setReal(item)"
                  ></i>

                  <i class="iconf iconshanchu" @click="removeItem(item,index)"></i>
                </div>
                <p slot="reference" class="p2 ellipsis2">{{ item.value }}</p>
              </el-popover>
            </li>
          </ul>
          <p
            class="more"
            v-show="personalInfo.length > 12"
            @click="personalInfoShowAll = !personalInfoShowAll"
          >
            查看更多<i
              :class="[
                'jt',
                'el-icon-d-arrow-right',
                !personalInfoShowAll ? '' : 'rot',
              ]"
            ></i>
          </p>
        </div>
        <div
          class="info-box"
          v-loading="loading1"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <p class="tit">教育经历</p>
          <ul class="basic-ul">
            <li>
              <p class="p1">时间</p>
              <p class="p1">教育单位</p>
              <p class="p1">教育程度&专业</p>
              <!-- <p class="set">操作</p> -->
            </li>
            <li v-for="(item, index) in eduInfo" :key="index">
              <p class="p1 ellipsis2">{{ item.time }}</p>
              <p class="p1 ellipsis2">{{ item.educationUnit }}</p>
              <p class="p1 ellipsis2" v-show="!!item.per_occupation">
                {{ item.per_occupation }}
              </p>
              <p
                class="p1 ellipsis2"
                v-show="!!item.per_title && !item.per_occupation"
              >
                {{ item.per_title }}
              </p>
              <p
                class="p1 ellipsis2"
                v-show="!item.per_title && !item.per_occupation"
              >
                {{ item.per_occupation }}
              </p>
              <!-- <div class="icon-box">
                <i class="iconf iconcheck-line" @click="sayDetailRa(item)"></i>
                <i class="iconf iconbianji" @click="setItemRa(item, 'edu')"></i>
                <i
                  class="iconf iconicon_anquan"
                  :class="item.verified ? 'active' : ''"
                  @click="setRealRa(item)"
                ></i>
                <i class="iconf iconshanchu" @click="removeItemRa(item)"></i>
              </div> -->
            </li>
          </ul>
          <div class="pagination">
            <el-pagination
              :hide-on-single-page="isShow"
              class="pagination"
              background
              layout="prev, pager, next"
              :total="eduTotal"
              :page-size="5"
              @current-change="handleChangeEdu"
            >
            </el-pagination>
          </div>
        </div>
        <div
          class="info-box"
          v-loading="loading2"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <p class="tit">工作经历</p>
          <ul class="basic-ul">
            <li>
              <p class="p1">时间</p>
              <p class="p1">工作单位</p>
              <p class="p1">职位</p>
              <!-- <p class="set">操作</p> -->
            </li>
            <li v-for="(item, index) in jobInfo" :key="index">
              <p slot="reference" class="p1 ellipsis2">
                {{ item.time }}
              </p>
              <p slot="reference" class="p1 ellipsis2">
                {{ item.workUnit }}
              </p>
              <p v-if="item.per_occupation != null" class="p1 ellipsis2">
                {{ item.per_occupation }}
              </p>
              <p v-else-if="item.per_title != null" class="p1 ellipsis2">
                {{ item.per_title }}
              </p>
              <p
                v-else-if="!item.per_title && !item.per_occupation"
                class="p1 ellipsis2"
              >
                {{ item.per_occupation }}
              </p>
              <!-- <div class="icon-box">
                <i class="iconf iconcheck-line" @click="sayDetailRa(item)"></i>
                <i class="iconf iconbianji" @click="setItemRa(item, 'work')"></i>
                <i class="iconf iconicon_anquan" :class="item.verified ? 'active' : ''" @click="setRealRa(item)"></i>
                <i class="iconf iconshanchu" @click="removeItemRa(item)"></i>
              </div> -->
            </li>
          </ul>
          <div class="pagination">
            <el-pagination
              :hide-on-single-page="jobIsShow"
              class="pagination"
              background
              layout="prev, pager, next"
              :total="jobTotal"
              :page-size="5"
              @current-change="handleChangeJob"
            >
            </el-pagination>
          </div>
        </div>
        <div
          class="info-box"
          v-loading="loading3"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <p class="tit">活动轨迹</p>
          <ul class="basic-ul act-ul">
            <li>
              <p class="p1">时间</p>
              <p class="p1">地点</p>
              <p class="p1">相关人</p>
              <p class="p1">活动详情</p>
              <!-- <span class="set">操作</span> -->
            </li>
            <li v-for="(item, index) in actInfo" :key="index">
              <p slot="reference" class="p1 ellipsis2">
                {{ item.time }}
              </p>
              <p slot="reference" class="p1 ellipsis2">
                {{ item.trackName }}
              </p>
              <p slot="reference" class="p1 ellipsis2">
                {{ item.other }}
              </p>
              <p slot="reference" class="p1 ellipsis2">
                {{ item.describe }}
              </p>
              <!-- <div class="icon-box">
                <i class="iconf iconcheck-line" @click="sayDetailRa(item)"></i>
                <i class="iconf iconbianji" @click="setItemRa(item, 'track')"></i>
                <i class="iconf iconicon_anquan" :class="item.verified ? 'active' : ''"@click="setRealRa(item)"></i>
                <i class="iconf iconshanchu" @click="removeItemRa(item)"></i>
              </div> -->
            </li>
          </ul>
          <div class="pagination">
            <el-pagination
              :hide-on-single-page="jobIsShow"
              class="pagination"
              background
              layout="prev, pager, next"
              :total="jobTotal"
              :page-size="5"
              @current-change="handleChangeAct"
            >
            </el-pagination>
          </div>
        </div>
      </div>
      <div class="body-right">
        <ul class="body-right-ul" v-loading="accountLoading">
          <li class="tit-li">
            <p class="tit">关联账号</p>
            <el-button
              class="addTwitter"
              icon="el-icon-plus"
              type="primary"
              size="small"
              @click="dialogVisible = true"
              >添加推特账号</el-button
            >
          </li>
          <li class="item" v-for="(item, index) in twitterAccount" :key="index">
            <div class="user">
              <img :src="item.headUrl" alt="" />
              <div>
                <p class="ellipsis">{{ item.accountName }}</p>
                <span v-if="!item.verified">可能关联推荐</span>
              </div>
              <el-button
                v-if="!item.verified"
                v-loading="item.loading"
                @click="_VerifyRelation(item)"
                class="guanlian"
                size="mini"
                plain
                >关联当前档案</el-button
              >
            </div>
            <p class="txt">{{ item.description }}</p>
          </li>
          <no-data :length="twitterAccount.length" :loading="accountLoading"></no-data>
        </ul>
        <ul class="body-right-ul" v-loading="archiveLoading">
          <li class="tit-li">
            <p class="tit">同名档案</p>
          </li>
          <li class="item" v-for="(item, index) in archives" :key="index">
            <div class="user">
              <img class="no-radius" :src="item.headUrl" alt="" />
              <div>
                <div class="d1">
                  <p>{{ item.entityName }}</p>
                  <el-button
                    v-loading="item.loading"
                    @click="_EntityMerge(item)"
                    class="guanlian"
                    size="mini"
                    plain
                    >合并档案</el-button
                  >
                </div>
                <p class="txt">{{ item.introduction }}</p>
              </div>
            </div>
          </li>
          <no-data :length="archives.length" :loading="archiveLoading"></no-data>
        </ul>
      </div>
    </div>
    <div class="cont-body" v-show="tabType != 0">
      <div class="body-left" v-loading="leftLoading">
        <ul class="item-ul">
          <li class="info-item" v-for="(item, index) in DataList" :key="index">
            <img class="pic" :src="item.headUrl" alt="" />
            <div class="info">
              <div class="name" v-show="childTabType != 2">
                {{ item.entityName }}
                <i class="iconf iconshanchu"></i>
              </div>
              <div class="name" v-show="childTabType == 2 && tabType == 1">
                {{ item.twitterName }}
                <span class="num">{{ `提及人物${item.twitterNumber}次` }}</span>
              </div>
              <div class="name" v-show="childTabType == 2 && tabType == 3">
                {{ item.entityName }}
                <span
                  class="num"
                  v-for="(label, indexs) in item.relationTypeList"
                  :key="indexs"
                  >{{ label }}</span
                >
              </div>
              <p class="txt ellipsis2" v-show="childTabType != 2">
                {{ item.evidence }}
              </p>
              <p
                class="txt ellipsis2"
                v-show="childTabType == 2 && tabType == 1"
              >
                {{ item.twitterContext }}
              </p>
              <p
                class="txt ellipsis2"
                v-show="childTabType == 2 && tabType == 3"
              >
                {{ item.evidence }}
              </p>
              <div class="label-list" v-show="childTabType != 2">
                <span
                  v-for="(label, indexs) in item.relationTypeList"
                  :key="indexs"
                  >{{ label }}</span
                >
              </div>
              <p class="href" v-show="childTabType == 2 && tabType == 1">
                {{ item.twitterUrl }}
              </p>
              <p class="href" v-show="childTabType == 2 && tabType == 3">
                {{ item.srcUrl }}
              </p>
            </div>
          </li>
        </ul>
        <no-data :length="DataList.length" :loading="leftLoading"></no-data>
        <el-pagination
          :hide-on-single-page="DataList.length <= 10"
          class="pagination"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page.sync="pageNum"
          prev-text="上一页"
          next-text="下一页"
          @current-change="handleChange"
        >
        </el-pagination>
      </div>
      <div class="body-right">
        <div class="chart-box" v-show="tabType != 3">
          <col-bar
            id="relationship"
            :title="childTabType == 2 ? '提及次数分布' : '关系分布'"
            :yAxisData="gxYAxisData"
            :seriesData="gxSeriesData"
          ></col-bar>
        </div>
        <div class="chart-box">
          <pie
            id="address"
            :title="childTabType == 2 ? '归属地分布' : '地域分布'"
            :seriesData="dySeriesData"
          ></pie>
        </div>
        <div class="chart-box">
          <bar
            id="label"
            :title="
              childTabType == 2
                ? '语种分布'
                : childTabType == 0
                ? '标签分布'
                : '机构类型'
            "
            :xAxisData="bqYAxisData"
            :seriesData="bqSeriesData"
          ></bar>
        </div>
      </div>
    </div>
    <el-dialog :visible.sync="dialogVisible" center width="900px">
      <div class="dialog-box">
        <div class="search">
          <input
            v-model="searchMsg"
            type="text"
            placeholder="请输入搜索关键词"
            autocomplete="off"
          />
          <i class="icon el-icon-search" @click="_GetTwitterRecord(false)"></i>
        </div>
        <ul
          class="dia-ul"
          v-loading="loadingDia"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
        >
          <li class="item" v-for="(item, index) in diaTwitterData" :key="index">
            <img :src="item.headUrl" alt="" />
            <div class="info-box">
              <div class="info">
                <p class="name">
                  <span>{{ item.twitterName }}</span>
                  <el-button
                    v-loading="item.loading"
                    class="btn"
                    type="primary"
                    @click="_AddRelation(item)"
                    @keyup.enter="_AddRelation(item)"
                    >关联档案</el-button
                  >
                </p>
                <p class="tit">{{ item.labelTypes }}</p>
              </div>
              <p class="all">
                <span>
                  <i class="iconf icontwitter"></i>
                  推文总数：{{ item.twitterAmout }}
                </span>
                <span>
                  <i class="iconf iconwujiaoxing"></i>
                  关注：{{ item.twitterAttention }}
                </span>
                <span>
                  <i class="iconf iconxin"></i>
                  粉丝：{{ item.twitterFans }}
                </span>
              </p>
            </div>
          </li>
        </ul>
        <p class="more" @click="_GetTwitterRecord(true)">
          <span> 查看更多 <i class="jt el-icon-d-arrow-right"></i> </span>
        </p>
      </div>
    </el-dialog>
    <verify
      :type="verifyType"
      :itemData="itemData"
      :dialogVer="dialogVer"
      :loading="loadingDia"
      :dataList="verifyData"
      @handleClose="handleClose"
      @handlePageNum="handlePageNum"
      @handleChangeAttr="handleChangeAttr"
    ></verify>

    <setRelation
      :type="relation"
      :itemData="itemData"
      :dialogVer="dialogVer2"
      @handleClose="handleClose"
      @handleChangeRat="handleChangeRat"
    ></setRelation>
  </div>
</template>

<script>
import {
  GetUserGroups,
  SynopsisDetails,
  GetPersonBasicInfo,
  PersonRelatedAccount,
  PersonTrackLocation,
  PersonWorkExperience,
  PersonEducationExperience,
  GetTwitterRecord,
  QuerySameNameEntity,
  AddRelation,
  VerifyRelation,
  EntityMerge,
  UpdateProperty,
  PersonOrgUpdate,
  InfluencePerson,
  BeImpacted,
  BeObjected,
  QueryRelationAnalysis,
  QueryPropertyAnalysis,
  GetInfluenceNumber,
  PersonOrgUpdata,
  GenerateReport,
  QueryEntityUpdateProgressRate,
  ModifyProperty,
  DeleteProperty,
  ViewPropertyEvidence,
  VerifyProperty,
  ModifyRelation,
  DeleteRelation,
  ViewRelationEvidence,
  TryUpdateEntity,
} from "@/api/personal";
import { tipErr, tipSuc, tipWarn, formatDate } from "@/utils/index";

export default {
  data() {
    return {
      // 人物属性修改
      dialogVer: false,
      verifyData: [],
      verifyPage: 0,
      verifyType: 1,
      // 修改带单位的数据弹窗
      dialogVer2: false,
      relation:'edu',
      itemData: null,
      // 添加关联账号弹窗
      dialogVisible: false,
      loadingDia: false,
      diaTwitterData: [],
      // 页面数据
      searchMsg: "",
      diaPageNum: 0,
      leftLoading: false,
      loading1: false,
      loading2: false,
      loading3: false,
      total: 100,
      pageSize: 10,
      pageNum: 1,
      entityId: null, //人物id
      tabType: 0, //选项卡
      childTabType: 0, //子级选项卡
      LabelButtonShow: false, //查看更多按钮显示开关
      LabelshowAll: false, //标签全部显示开关
      personalInfoShowAll: false, //基本信息全部显示开关
      /* 人物基本信息 */
      personal: {
        name: "",
        updateTime: "",
        progress: "",
        label: [],
        organization: "",
      },
      personalInfo: [],
      eduTotal: 5,
      eduTotalPageNum: 0,
      eduInfo: [],
      jobTotal: 5,
      jobTotalPageNum: 0,
      jobInfo: [],
      actTotal: 5,
      actTotalPageNum: 0,
      actInfo: [],
      /**基本信息结束 */
      accountLoading:false,
      archiveLoading:false,
      twitterAccount: [],
      archives: [],
      // 影响、被影响、反对数据
      DataList: [],
      //关系分布数据
      gxYAxisData: [],
      gxSeriesData: [],
      //地域分布
      dySeriesData: [],
      //标签分布数据
      bqYAxisData: [],
      bqSeriesData: [],
      perNumber: 0,
      orgNumber: 0,
      twitterNumber: 0,
    };
  },
  computed: {
    isShow: function() {
      return this.eduTotal <= 5 ? true : false;
    },
    jobIsShow: function() {
      return this.jobTotal <= 5 ? true : false;
    },
    actIsShow: function() {
      return this.actTotal <= 5 ? true : false;
    },
  },
  created() {
    this.entityId = this.$route.query.entityId;
    this.personal.name = this.$route.query.name;
    this.personal.organization = this.$route.query.organization;
    this.personal.abstractType = this.$route.query.abstractType;
    this._GetPersonBasicInfo();
    this._PersonEducationExperience(this.eduTotalPageNum);
    this._PersonWorkExperience(this.jobTotalPageNum);
    this._PersonTrackLocation(this.actTotalPageNum);
    this._SynopsisDetails();
    this._PersonRelatedAccount();
    this._QuerySameNameEntity();
    this._PersonOrgUpdata()
  },
  async mounted() {},
  beforeDestroy(){
    clearTimeout(this.timeOut)
    this.timeOut = null
  },
  methods: {
    _UpdateProperty() {
      const name = this.personal.name;
      this.$prompt("姓名", "修改名字", {
        inputValue: name,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputValidator: function(msg) {
          if (msg) return true;
          else return false;
        },
        inputErrorMessage: "内容不能为空",
      })
        .then(async ({ value }) => {
          let { data, code, msg } = await UpdateProperty({
            entityId: this.entityId,
            newPropertyValue: value,
            oldPropertyValue: this.personal.name,
            propertyKey: "PER_NAME",
          });
          if (code == 1) {
            tipSuc("修改成功");
            this.personal.name = value;
          } else {
            tipErr(msg);
          }
        })
        .catch(() => {});
    },
    async _PersonOrgUpdata() {
      let res = await PersonOrgUpdata({
        appkey: "personOrgUpdata",
        entityName: this.personal.name,
        entityId: this.entityId,
        type: "PERSON",
      });
      let { data, code, msg } = await TryUpdateEntity({
        entityId: this.entityId,
        type:'PERSON'
      });
      
      if(code == 1){
        await this._QueryEntityUpdateProgressRate();
      }else{
        tipErr('更新失败')
      }
      
    },
    async _GenerateReport() {
      let { data, code, msg } = await GenerateReport({
       
         entityName: this.personal.name,
        entityId: this.entityId,
        verify: false,
      });
    },
    async _QueryEntityUpdateProgressRate() {
      let { data, code, msg } = await QueryEntityUpdateProgressRate({
        entityId: this.entityId
      });
      if (code == 1) {
        this.personal.progress = data.progress;
        if(data.progress<100){
         this.timeOut =  setTimeout(()=>{
           console.log(1)
           clearTimeout(this.timeOut)
           this.timeOut=null
           this._QueryEntityUpdateProgressRate()
        },20000)
        }
      }
    },
    async _GetPersonBasicInfo() {
      let { data, code, msg } = await GetPersonBasicInfo({
        entityId: this.entityId,
      });
      if (code == 1) {
        this.personalInfo = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _SynopsisDetails() {
      let { data, code, msg } = await SynopsisDetails({
        entityId: this.entityId,
        twitter: false,
        langType: "zh",
        type: "PERSON",
      });
      if (code == 1) {
        data.updateTime = formatDate(data.updateTime, "yy-MM-dd hh:mm:ss");
        this.personal = Object.assign(this.personal, data);
        this.$nextTick(function() {
          let height = this.$refs.labelList.offsetHeight;
          if (height && height > 50) {
            this.LabelButtonShow = true;
            this.LabelshowAll = true;
          }
        });
      } else {
        tipErr(msg);
      }
    },
    async _PersonEducationExperience(index) {
      this.loading1 = true;
      let { data, total, code, msg } = await PersonEducationExperience({
        entityId: this.entityId,
        row: 5,
        start: index ? index * 5 : 0,
      });
      this.loading1 = false;
      if (code == 1) {
        this.eduTotal = total;
        this.eduTotalPageNum++;
        data.map((item) => {
          item.time = formatDate(item.time, "yy");
          return item;
        });
        this.eduInfo = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _PersonWorkExperience(index) {
      this.loading2 = true;
      let { data, total, code, msg } = await PersonWorkExperience({
        entityId: this.entityId,
        row: 5,
        start: index ? index * 5 : 0,
      });
      this.loading2 = false;
      if (code == 1) {
        this.jobTotal = total;
        this.jobTotalPageNum++;
        data.map((item) => {
          item.time = formatDate(item.time, "yy");
          return item;
        });
        this.jobInfo = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _PersonTrackLocation(index) {
      this.loading3 = true;
      let { data, total, code, msg } = await PersonTrackLocation({
        entityId: this.entityId,
        row: 5,
        start: index ? index * 5 : 0,
      });
      this.loading3 = false;
      if (code == 1) {
        this.actTotal = total;
        this.actTotalPageNum++;
        data.map((item) => {
          item.time = formatDate(item.time, "yy");
          return item;
        });
        this.actInfo = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _PersonRelatedAccount() {
      this.accountLoading=true
      let { data, code, msg } = await PersonRelatedAccount({
        entityId: this.entityId,
        row: 10,
        start: 0,
      });
      this.accountLoading=false
      if (code == 1) {
        this.twitterAccount = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _GetTwitterRecord(index) {
      if (this.searchMsg == "") {
        tipWarn("请输入关键词~");
        return;
      }
      if (this.loadingDia) return;
      this.loadingDia = true;
      let { data, code, msg } = await GetTwitterRecord({
        entityId: this.entityId,
        searchContent: this.searchMsg,
        recordScope: 0,
        row: 10,
        start: index ? this.diaPageNum * 10 : 0,
        type: "ACCOUNT_TWITTER",
      });
      this.loadingDia = false;
      if (code == 1) {
        this.diaPageNum = index ? this.diaPageNum + 1 : 1;
        data.twitterBasicInfoList.forEach((item) => {
          if (Array.isArray(item.labelTypes)) {
            item.labelTypes = item.labelTypes.join(",");
          }
        });
        this.diaTwitterData = [...data.twitterBasicInfoList];
      } else {
        tipErr(msg);
      }
    },
    async _AddRelation(item, json) {
      if (item.loading && 1) return;
      this.$set(item, "loading", true);
      let params = {
        inVertexId: item.entityId,
        outVertexId: this.entityId,
        edgeLabel: "PER_twitter_ATW",
        knowledgeFeature: {},
        mergerType: 1,
      };
      if (json) {
        params = Object.assign(params, json);
      }
      let { data, code, msg } = await AddRelation(params);
      item.loading = false;
      if (code == 1) {
        if (msg == "FAILED") {
          tipErr("关联失败");
        } else {
          if (data.mergerType == 2) {
            let me = this;
            this.$confirm(
              "",
              `此账号已经关联了档案${data.nameList[0]}，是否继续关联？如果关联的话，档案${data.nameList[0]}和档案${data.nameList[1]}将会被合并`,
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                center: true,
              }
            )
              .then(({ value }) => {
                me._TwitterAddRelation(item, { mergerType: 2 });
              })
              .catch(() => {});
          } else {
            tipSuc("关联成功");
            this._PersonRelatedAccount();
          }
        }
      } else {
        tipErr("关联失败");
      }
    },
    async _QuerySameNameEntity() {
      this.archiveLoading=true
      let { data, code, msg } = await QuerySameNameEntity({
        entityId: this.entityId,
        row: 10,
        start: 0,
        entityNames: [this.personal.name],
        entityType: "PERSON",
        langType: "zh",
      });
      this.archiveLoading= false
      if (code == 1) {
        data.forEach((item) => {
          if (Array.isArray(item.introduction)) {
            item.introduction = item.introduction.join(",");
          }
        });
        this.archives = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _VerifyRelation(item) {
      if (item.loading && 1) return;
      this.$set(item, "loading", true);
      let { data, code, msg } = await VerifyRelation({
        outVertexId: this.entityId,
        inVertexId: item.entityId,
        edgeLabel: "PER_twitter_ATW",
        cancelOrVerify: 1,
        knowledgeFeature: {},
      });
      item.loading = false;
      if (code == 1) {
        if (msg == "FAILED") {
          tipErr("关联失败");
        } else {
          tipSuc("关联成功");
        }
      } else {
        tipErr("关联失败");
      }
    },
    async _EntityMerge(item) {
      if (item.loading && 1) return;
      this.$set(item, "loading", true);
      let { data, code, msg } = await EntityMerge({
        entityName: this.personal.name,
        entityIds: [
          this.entityId,
          item.entityId,
        ],
        entityType: "PERSON",
      });
      item.loading = false;
      if (code == 1) {
        if (msg == "FAILED") {
          tipErr("融合失败");
        } else {
          tipSuc(msg);
        }
      } else {
        tipErr("融合失败");
      }
    },
    async _getPersonList(index) {
      if (this.leftLoading) return;
      this.$set(this, "leftLoading", true);
      let params = this.setInfluenParams();
      params = Object.assign(params, {
        entityId: this.entityId,
        influenceType: this.tabType,
        rows: this.pageSize,
        start: index ? index * 10 : 0,
      });
      if (this.tabType == 1) {
        var { data, code, msg, total } = await InfluencePerson(params);
      } else if (this.tabType == 2) {
        var { data, code, msg, total } = await BeImpacted(params);
      } else if (this.tabType == 3) {
        var { data, code, msg, total } = await BeObjected(params);
      }
      this.leftLoading = false;
      if (code == 1) {
        this.total = total;
        data.forEach((item) => {
          if (item.relationTypeList && Array.isArray(item.relationTypeList)) {
            for (let i = 0; i < item.relationTypeList.length; i++) {
              item.relationTypeList[i] = this.setLabelTxt(
                item.relationTypeList[i]
              );
            }
          }
        });
        this.DataList = [...data];
      } else {
        tipErr(msg);
      }
    },
    async _QueryRelationAnalysis() {
      let entityType = this.setEntityType();
      let { data, code, msg } = await QueryRelationAnalysis({
        entityId: this.entityId,
        entityType: entityType,
        influenceType: this.tabType,
        rows: 10,
        start: 0,
      });
      if (code == 1) {
        let gxSeriesData = [],
          gxYAxisData = [];
        for (let key in data) {
          gxYAxisData.push(this.setLabelTxt(key));
          gxSeriesData.push(data[key]);
        }
        this.gxYAxisData = [...gxYAxisData];
        this.gxSeriesData = [...gxSeriesData];
      } else {
        tipErr(msg);
      }
    },
    async _QueryPropertyAnalysis() {
      let entityType = this.setEntityType();
      let { data, code, msg } = await QueryPropertyAnalysis({
        entityId: this.entityId,
        entityType: entityType,
        influenceType: this.tabType,
        rows: 10,
        start: 0,
      });
      if (code == 1) {
        let bqYAxisData = [],
          bqSeriesData = [];
        if (this.childTabType == 0) {
          this.dySeriesData = [...(data.PER_WORK_PLACE_P || [])];
          if (data.PER_LABEL != null) {
            data.PER_LABEL.forEach((item) => {
              bqYAxisData.push(item.name);
              bqSeriesData.push(item.value);
            });
          }
        } else if (this.childTabType == 1) {
          this.dySeriesData = [...(data.ORG_LOCATION_P || [])];
          if (data.ORG_TYPE != null) {
            data.ORG_TYPE.forEach((item) => {
              bqYAxisData.push(item.name);
              bqSeriesData.push(item.value);
            });
          }
        } else if (this.childTabType == 2) {
          this.dySeriesData = [...(data.ATW_LOCATION || [])];
          if (data.ATW_LANG != null) {
            data.ATW_LANG.forEach((item) => {
              bqYAxisData.push(item.name);
              bqSeriesData.push(item.value);
            });
          }
        }
        this.bqYAxisData = [...bqYAxisData];
        this.bqSeriesData = [...bqSeriesData];
      } else {
        tipErr(msg);
      }
    },
    async _GetInfluenceNumber() {
      let { data, code, msg } = await GetInfluenceNumber({
        entityId: this.entityId,
        entityType: "PER_PER",
        influenceType: this.tabType,
        rows: 10,
        start: 0,
      });
      if (code == 1) {
        this.perNumber = data.perNumber;
        this.orgNumber = data.orgNumber;
        this.twitterNumber = data.twitterNumber;
      } else {
        tipErr(msg);
      }
    },
    async _ModifyProperty(nVal, oVal) {
      let { data, code, msg } = await ModifyProperty({
        id: oVal.id,
        entityId: this.entityId,
        oldPropertyKey: oVal.key,
        oldPropertyValue: oVal.value,
        newPropertyKey: oVal.key,
        newPropertyValue: nVal.value,
        appkey: "modifyProperty",
        url: nVal.url,
        evidence: nVal.evidence,
      });
      if (code == 1) {
        this.dialogVer = false;
        oVal.value = nVal.value;
        tipSuc("修改成功!");
      } else {
        tipErr("修改失败");
      }
    },
    async _DeleteProperty(item) {
      let { data, code, msg } = await DeleteProperty({
        entityId: this.entityId,
        propertyKey: item.key,
        propertyValue: item.value,
        appkey: "deleteProperty",
      });
      if (code == 1) {
        tipSuc("删除成功");
        return true
      } else {
        tipErr("操作失败");
        return false
      }
    },
    async _ViewPropertyEvidence() {
      if (this.loadingDia) return;
      this.loadingDia = true;
      let { data, code, msg } = await ViewPropertyEvidence({
        entityId: this.entityId,
        entityName: this.personal.name,
        propertyKey: this.itemData.key,
        propertyValue: this.itemData.value,
        start: this.verifyPage * 10,
        rows: 10,
        sortField: "PUBLISHER_TIME",
        entityType: "PERSON",
        linked: true,
        appkey: "viewPropertyEvidence",
      });
      this.loadingDia = false;
      if (code == 1) {
        this.verifyData = [...this.verifyData, ...data];
        this.verifyPage++;
      }
    },
    async _VerifyProperty(item) {
      let { data, code, msg } = await VerifyProperty({
        entityId: this.entityId,
        propertyKey: item.key,
        propertyValue: item.value,
        cancelOrVerify: item.verified?1:0, //0验证，1取消验证
        appkey: "verifyProperty",
      });
      if (code == 1) {
        item.verified = !item.verified;
        tipSuc("操作成功");
      } else {
        tipErr("操作失败");
      }
    },
    async _ModifyRelation(nVal, oVal) {
      let { data, code, msg } = await ModifyRelation({
        id: oVal.id,
        entityId: this.entityId,
        oldRelationKey: oVal.key,
        oldRelationValue: oVal.value,
        newRelationKey: oVal.key,
        newRelationValue: nVal.value,
        appkey: "modifyRelation",
        url: nVal.url,
        evidence: nVal.evidence,
      });
      if (code == 1) {
        this.dialogVer = false;
        oVal.value = nVal.value;
        tipSuc("修改成功!");
      } else {
        tipErr("修改失败");
      }
    },
    async _DeleteRelation(item) {
      let { data, code, msg } = await DeleteRelation({
        entityId: this.entityId,
        RelationKey: item.key,
        RelationValue: item.value,
        appkey: "deleteRelation",
      });
      if (code == 1) {
        tipSuc("删除成功");
      } else {
        tipErr("操作失败");
      }
    },
    async _ViewRelationEvidence() {
      if (this.loadingDia) return;
      this.loadingDia = true;
      let { data, code, msg } = await ViewRelationEvidence({
        entityId: this.entityId,
        entityName: this.personal.name,
        RelationKey: this.itemData.key,
        RelationValue: this.itemData.value,
        start: this.verifyPage * 10,
        rows: 10,
        sortField:"PUBLISHER_TIME",
        entityType:"PERSON",
        linked:true,
        "appkey":"viewPropertyEvidence",
        "knowledgeFeature":{
          "gmt_create":1605583257298,
          "score":0.5,
          "evidenceNumber":1,
          "importance":0.5,
          "verified":false,
          "time":1604592000000,
          "time_str":"今年11月6日",
          "gmt_modified":1605611268137,
          "version":"zhL0.0.6|zhL0.0.8",
          "distinctEvidenceNumber":1,
          "linked":true
        }
      });
      this.loadingDia = false;
      if (code == 1) {
        this.verifyData = [...this.verifyData, ...data];
        this.verifyPage++;
      }
    },
    async _VerifyRelation2(item) {
      let { data, code, msg } = await VerifyRelation({
        entityId: this.entityId,
        RelationKey: item.key,
        RelationValue: item.value,
        cancelOrVerify: !item.verified, //0验证，1取消验证
        appkey: "verifyRelation",
      });
      if (code == 1) {
        item.verified = !item.verified;
        tipSuc("操作成功");
      } else {
        tipErr("操作失败");
      }
    },
    setLabelTxt(txt) {
      let msg;
      if (txt == "PER_aware_of_PER") {
        msg = "可能认识";
      } else if (txt == "PER_relatives_PER") {
        msg = "亲属关系";
      } else if (txt == "PER_work_PER") {
        msg = "亲属关系";
      } else if (txt == "PER_be_mention_PER") {
        msg = "被提及";
      } else if (txt == "PER_friend_PER") {
        msg = "朋友关系";
      } else if (txt == "PER_management_ORG") {
        msg = "管理层";
      } else if (txt == "PER_cooperation_ORG") {
        msg = "合作关系";
      } else if (txt == "ORG_competition_ORG") {
        msg = "对立关系";
      } else if (txt == "PER_competition_ORG") {
        msg = "对立关系";
      } else if (txt == "ATW_competition_ORG") {
        msg = "对立关系";
      } else if (txt == "a") {
        msg = "1-50";
      } else if (txt == "b") {
        msg = "50-100";
      } else if (txt == "c") {
        msg = "100-200";
      } else if (txt == "d") {
        msg = "200-500";
      } else if (txt == "e") {
        msg = "500次以上";
      }
      return msg;
    },
    setInfluenParams() {
      let params;
      if (this.childTabType == 0) {
        params = {
          entityType: "PER_PER",
          relationFilters: [
            "PER_relatives_PER",
            "PER_aware_of_PER",
            "PER_work_PER",
            "PER_be_mention_PER",
            "PER_friend_PER",
          ],
        };
      } else if (this.childTabType == 1) {
        params = {
          entityType: "PER_ORG",
        };
      } else if (this.childTabType == 2) {
        params = {
          entityType: "PER_ATW",
        };
      }

      return params;
    },
    setEntityType() {
      let entityType;
      if (this.childTabType == 0) {
        entityType = "PER_PER";
      } else if (this.childTabType == 1) {
        entityType = "PER_ORG";
      } else if (this.childTabType == 2) {
        entityType = "PER_ATW";
      }
      return entityType;
    },
    setTabType(index) {
      this.tabType = index;
      this.childTabType = 0;
      if (!!index) {
        this.setChildTabType(0);
        this._GetInfluenceNumber();
      }
    },
    setChildTabType(index) {
      this.childTabType = index;
      this.pageNum = 1;
      let myEvent = new Event("resize");
      window.dispatchEvent(myEvent);
      this._getPersonList();
      if (this.tabType != 3) {
        this._QueryRelationAnalysis();
      }
      this._QueryPropertyAnalysis();
    },
    linkSetDetail() {},
    sayDetail(item) {
      this.verifyType = 1;
      this.dialogVer = true;
      this.verifyData = [];
      this.verifyPage = 0;
      this.itemData = { ...item };
      this._ViewPropertyEvidence();
    },
    setItem(item, index, txt) {
      this.verifyType = 2;
      this.dialogVer = true;
      this.itemData = item;
    },
    setReal(item) {
      this._VerifyProperty(item);
    },
    removeItem(item, index) {
      this.$confirm("", "确定删除吗？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
      })
        .then(async ({ value }) => {
        
        let isOK = await this._DeleteProperty(item)
         if(isOK){
             let arr;
            arr = this.personalInfo.filter((items, indexs) => {
              return index != indexs;
            });
            this.personalInfo = [...arr];
         }
        })
        .catch(() => {});
    },
    sayDetailRa(item) {
      this.verifyType = 1;
      this.dialogVer = true;
      this.verifyData = [];
      this.verifyPage = 0;
      this.itemData = { ...item };
      this._ViewRelationEvidence();
    },
    setItemRa(item,type) {
      this.relation = type;
      this.dialogVer2 = true;
      this.itemData = item;
    },
    setRealRa(item) {
      this._VerifyRelation2(item);
    },
    removeItemRa(item) {
      this.$confirm("", "确定删除吗？", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
      })
        .then(({ value }) => {
          let arr;
          arr = this[type].filter((items, indexs) => {
            return index != indexs;
          });
          this[type] = [...arr];
        })
        .catch(() => {});
    },
    handlePageNum(val) {
      if(val==3){
        this._ViewRelationEvidence()
      }else{
        this._ViewPropertyEvidence()
      }
    },
    handleClose() {
      this.dialogVer = false;
      this.dialogVer2 = false;
    },
    handleChangeAttr(json) {
      this._ModifyProperty(json.newVal, json.oldVal);
    },
    handleChangeRat(json) {
      this._ModifyRelation(json.newVal, json.oldVal);
    },
    handleChangeEdu(index) {
      this._PersonEducationExperience(index - 1);
    },
    handleChangeJob(index) {
      this._PersonWorkExperience(index - 1);
    },
    handleChangeAct(index) {
      this._PersonTrackLocation(index - 1);
    },
    handleChange(index) {
      this._getPersonList(index - 1);
    },
  },
};
</script>

<style lang="scss" scoped src="@/assets/css/detail.scss"></style>
